import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import java.util.Scanner;
import org.json.*;
//import org.json.simple.*;

public class TestClass {

    private static String API_KEY = "xGN81IwCaUMozMrNruRKSADVnprDMsnX";

    public static String getApiUri(String uri) {
        return "http://www.plurk.com/API" + uri;
    }

    public final static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
    	String username = new String();
        String password = new String();
    	
        System.out.print("Username:");
        username = scanner.next();
        System.out.print("Password:");
        password = scanner.next();
        
    	HttpClient httpclient = new DefaultHttpClient();

        HttpGet httpget = new HttpGet(getApiUri("/Users/login?"+
                            "api_key=" + API_KEY + "&" +
                            "username=" + username + "&" +
                            "password=" + password
                          ));

        ResponseHandler responseHandler = new BasicResponseHandler();
        System.out.println(httpclient.execute(httpget, responseHandler));
        JSONObject obj = new JSONObject(httpclient.execute(httpget, responseHandler).toString());
        System.out.println(obj.get("user_info"));
        JSONObject objUserInfo = new JSONObject(obj.get("user_info").toString());
        JSONArray arrPlurks = new JSONArray(obj.get("plurks").toString());
        System.out.println(arrPlurks.get(2));

        
        
        
        

//        httpget = new HttpGet(getApiUri("/Timeline/plurkAdd?"+
//                "api_key=" + API_KEY + "&" +
//                "content=" + "Hello+nasty" + "&" +
//                "qualifier=" + "says" + "&" +
//                "lang=tr_ch"
//        ));
//
//        responseHandler = new BasicResponseHandler();
//        System.out.println(httpclient.execute(httpget, responseHandler));

        httpclient.getConnectionManager().shutdown();
    }
}
